<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<!-- 下拉框 -->
<link rel="stylesheet" href="static/ace/css/chosen.css" />
<!-- jsp文件头和头部 -->
<%@ include file="../index/top.jsp"%>
<!-- 日期框 -->
<link rel="stylesheet" href="static/ace/css/datepicker.css" />
</head>
<body class="no-skin">

	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
						
						<!-- 检索  -->
						<form action="period/selectGoodsList.do" method="post" name="goodsForm" id="goodsForm">
						<table style="margin-top:5px;">
						<%-- 	<tr>
								<td>
									<div class="nav-search">
									<span class="input-icon">
										<input class="nav-search-input" autocomplete="off" id="nav-search-input" type="text" name="keywords" value="${pd.keywords}" placeholder="这里输入商品名称" />
										<i class="ace-icon fa fa-search nav-search-icon"></i>
									</span>
									</div>
								</td>
								<td style="vertical-align:top;padding-left:2px;">
								 	<select class="chosen-select form-control" name="state" id="state" data-placeholder="状态" style="vertical-align:top;width: 120px;">
									<option value="">全部</option>
									<option value="01" <c:if test="${pd.state=='01'}">selected</c:if>>上架</option>
									<option value="00" <c:if test="${pd.state=='00'}">selected</c:if>>下架</option>
								  	</select>
								</td>
								<td style="vertical-align:top;padding-left:2px;">
								 	<select class="chosen-select form-control" name="stockState" id="stockState" data-placeholder="缺货状态" style="vertical-align:top;width: 120px;">
									<option value="">全部</option>
									<option value="00"  <c:if test="${pd.stockState=='00'}">selected</c:if>>正常</option>
									<option value="01"  <c:if test="${pd.stockState=='01'}">selected</c:if>>缺货</option>
								  	</select>
								</td>
								<c:if test="${QX.cha == 1 }">
								<td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="searchs();"  title="检索"><i id="nav-search-icon" class="ace-icon fa fa-search bigger-110 nav-search-icon blue"></i></a></td>
								</c:if>
							</tr> --%>
						</table>
						<!-- 检索  -->
					
						<table id="simple-table" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
                            <input type="hidden" id="countId" value="${pd.countId }"/>
							<thead>
								<tr>
									<th class="center" style="width:50px;">选中</th>
									<th class="center">ID</th>
									<th class="center">批次号</th>
                                    <th class="center">区域名称</th>
                                    <th class="center">种植日期</th>
                                    <th class="center">库存</th>
                                    <th class="center">已购数量</th>
								</tr>
							</thead>
													
							<tbody>
								
							<!-- 开始循环 -->	
							<c:choose>
								<c:when test="${not empty areaGoods}">
									<c:if test="${QX.cha == 1 }">
									<c:forEach items="${areaGoods}" var="goods" varStatus="vs">
										<tr>
											<td class="center"><input type="radio" id = "goodsId" name="goodsId" value="${goods.id}" num="${goods.num-goods.take_num }" <c:if test="${goods.id ==pd.countId}">checked="checked"</c:if>></td>
											<td class="center">${goods.id }</td>
											<td class="center">${goods.batch_number }</td>
                                            <td class="center">${goods.name }</td>
                                            <td class="center">${goods.birthday }</td>
                                            <td class="center">${goods.num-goods.take_num }</td>
                                            <td class="center">${goods.take_num }</td>
										</tr>
									</c:forEach>
									</c:if>
									<c:if test="${QX.cha == 0 }">
										<tr>
											<td colspan="10" class="center">您无权查看</td>
										</tr>
									</c:if>
								</c:when>
								<c:otherwise>
									<tr class="main_info">
										<td colspan="10" class="center">没有相关数据</td>
									</tr>
								</c:otherwise>
							</c:choose>
							
							<input type="hidden" id="ids" name="ids" value=""/>
                            <input type="hidden" id="num" name="num" value=""/>
							</tbody>
						</table>
						
					<div class="page-header position-relative">
					<table style="width:100%;">
						<tr>
								<td style="vertical-align:top;">
									
								</td>
								<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
							</tr>
					</table>
					</div>
					<div id="zhongxin"></div>
					</form>
	
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->
	</div>
	<!-- /.main-container -->

	<!-- basic scripts -->
	<!-- 页面底部js¨ -->
	<%@ include file="../index/foot.jsp"%>
	<!-- 删除时确认窗口 -->
	<script src="static/ace/js/bootbox.js"></script>
	<!-- ace scripts -->
	<script src="static/ace/js/ace/ace.js"></script>
	<!-- 日期框 -->
	<script src="static/ace/js/date-time/bootstrap-datepicker.js"></script>
	<!-- 下拉框 -->
	<script src="static/ace/js/chosen.jquery.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	</body>

<script type="text/javascript">
$(top.hangge());
//检索
function searchs(){
	top.jzts();
	$("#goodsForm").submit();
}

$(function(){
	$(":radio").on("change",function(){
		var id = $(this).val();
		var num = $(this).attr("num");
		$("#ids").val(id);
		$("#num").val(num);
		if(num<=0){
			alert("此商品已被订购完");
			$("#num").val("");
			$("#ids").val("");
			return false;
		}
		$.ajax({
			type: "POST",
			url: '<%=basePath%>period/checkCount.do',
	    	data: {'id':id},
			success: function(data){
			    if("success"==data){
			    	alert("此商品已加入期次，请重新选择商品!");
			    	$("#num").val("");
					$("#ids").val("");
			    	return false;
			   }
			}
		});
		
	})
})



		
</script>
</html>
